#ifndef __SENSOR_H
#define __SENSOR_H

#include <stdint.h>
#include "msp.h"
#include "controller.h"

// NOTE: MAKE SURE THIS JIVES WITH THE STRUCT DEF BELOW
#define NUM_SENSORS 8

#define IR_SENSOR_RESULT_SHIFT 4
#define EF_SENSOR_RESULT_SHIFT 4

#define TA1_ON TA1CTL = TASSEL_2 | ID_0 | MC_1 | TACLR
#define TA1_OFF TA1CTL = MC_0
#define ENABLE_SENSOR_INTERRUPTS TA1CCTL0 |= CCIE
#define DISABLE_SENSOR_INTERRUPTS TA1CCTL0 &= ~CCIE 

typedef enum {
    /*
     * LED1 {0,0,0} Forward
     * LED2 {0,0,1} Reverse
     * LED3 {0,1,0} Right
     * LED4 {0,1,1} Left
     * LED5 {1,0,0} Down*/
    FORWARD = 0,
    REVERSE,
    RIGHT,
    LEFT,
    DOWN,
    EFIELD1,
    EFIELD2
} sensor_sel_t;

typedef enum {
    /*
     * LED1 {0,0,0} Forward
     * LED2 {0,0,1} Reverse
     * LED3 {0,1,0} Right
     * LED4 {0,1,1} Left
     * LED5 {1,0,0} Down*/
    LOW = 0,
    HIGH
} state_t;

void initalize_infrared();
void set_ir_led(sensor_sel_t direction, int8_t state);
void select_sensor(sensor_sel_t sensor);

enum sensor{
    IR = 0,
    EF
};

typedef struct {
    opcode_t op;
    
    // IR 
    int16_t ir_front;
    int16_t ir_reverse;
    int16_t ir_left;
    int16_t ir_right;
    int16_t ir_down;
    
} sensor_data_t;

// Initializes everything needed for the sensors
void initialize_sensors(void);

// Called from main to do everything needed to save sensor results into sdp
//void gather_sensor_data (sensor_data_t *sdp);
void gather_sensor_data (int16_t *sdp);

#endif
